<?php
/**
* @file $Id: PrintStudentInfo.php 556 2007-06-04 05:19:08Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

Widgets('mailing_labels');
Widgets('document_template');
/*Widgets('course');
Widgets('request');
Widgets('activity');
Widgets('absences');
Widgets('gpa');
Widgets('class_rank');
Widgets('letter_grade');
Widgets('eligibility');*/
Widgets('all');
$extra['force_search'] = true;

if(!$_REQUEST['search_modfunc'] || $_REQUEST['search_modfunc']=='search' || $_FOCUS['modules_search'])
{
	DrawHeader(ProgramTitle());

	$extra['new'] = true;
	$extra['action'] .= "&_FOCUS_PDF=true";

	$extra['second_col'] .= '<TABLE><TR>';
	$categories_RET = DBGet(DBQuery("SELECT ID,TITLE FROM STUDENT_FIELD_CATEGORIES ORDER BY SORT_ORDER,TITLE"));
	foreach($categories_RET as $category)
	{
		if(AllowUse('Students/Student.php?category_id='.$category['ID']))
		if(++$i%2)
			$extra['second_col'] .= '</TR><TR>';
		$extra['second_col'] .= '<TD><INPUT type=checkbox name=categories['.$category['ID'].'] value=Y CHECKED>'.$category['TITLE'].'</TD>';
	}
	$extra['second_col'] .= '</TR></TABLE>';

	Search('student_id',$extra);
}
else
{
	$extra['functions']['GRADE_ID'] = 'return';
	$RET = GetStuList($extra);
	
	if(count($RET))
	{
		include($staticpath.'modules/Students/includes/functions.php');
		$categories_RET = DBGet(DBQuery("SELECT ID,TITLE FROM STUDENT_FIELD_CATEGORIES WHERE ID>3 ORDER BY SORT_ORDER,TITLE"));
		$handle = PDFStart();
		foreach($RET as $student)
		{
			$_SESSION['student_id'] = $student['STUDENT_ID'];
			unset($_FOCUS['DrawHeader']);

			if($_REQUEST['mailing_labels']=='Y')
				echo '<BR><BR><BR>';
			DrawHeader(Config('TITLE').' '._('Student Info'));
			DrawHeader($student['FULL_NAME'],$student['STUDENT_ID']);
			DrawHeader($student['GRADE_ID'],GetSchool(UserSchool()));
			DrawHeader(ProperDate(DBDate()));

			if($_REQUEST['mailing_labels']=='Y')
				echo '<BR><BR><TABLE width=100%><TR><TD width=50> &nbsp; </TD><TD>'.$student['MAILING_LABEL'].'</TD></TR></TABLE><BR>';

			if($_REQUEST['categories'][1]=='Y')
			{
				include($staticpath.'modules/Students/includes/General_Info.inc.php');
				echo '<BR><BR>';
			}
			if($_REQUEST['categories'][3]=='Y')
			{
				echo '<!-- NEED 4 -->';
				DrawHeader(_('Addresses & Contacts'));
				$addresses_RET = DBGet(DBQuery("SELECT a.ADDRESS_ID,sjp.STUDENT_RELATION,p.PERSON_ID,p.FIRST_NAME,p.MIDDLE_NAME,p.LAST_NAME,a.ADDRESS,a.CITY,a.STATE,a.ZIPCODE,a.PHONE,a.MAIL_ADDRESS,a.MAIL_CITY,a.MAIL_STATE,A.MAIL_ZIPCODE,sjp.CUSTODY,sjp.EMERGENCY,sja.MAILING,sja.RESIDENCE FROM ADDRESS a,STUDENTS_JOIN_ADDRESS sja,STUDENTS_JOIN_PEOPLE sjp,PEOPLE p WHERE a.ADDRESS_ID=sja.ADDRESS_ID AND a.ADDRESS_ID=sjp.ADDRESS_ID AND sjp.STUDENT_ID=sja.STUDENT_ID AND sjp.PERSON_ID=p.PERSON_ID AND sja.STUDENT_ID='".UserStudentID()."' 
					UNION SELECT a.ADDRESS_ID,'No Contacts' AS STUDENT_RELATION,NULL AS PERSON_ID,NULL AS FIRST_NAME,NULL AS MIDDLE_NAME,NULL AS LAST_NAME,a.ADDRESS,a.CITY,a.STATE,a.ZIPCODE,a.PHONE,a.MAIL_ADDRESS,a.MAIL_CITY,a.MAIL_STATE,A.MAIL_ZIPCODE,NULL,sja.MAILING,sja.RESIDENCE AS CUSTODY,sja.RESIDENCE AS EMERGENCY FROM ADDRESS a,STUDENTS_JOIN_ADDRESS sja WHERE a.ADDRESS_ID=sja.ADDRESS_ID AND sja.STUDENT_ID='".UserStudentID()."' AND NOT EXISTS (SELECT '' FROM STUDENTS_JOIN_PEOPLE sjp WHERE sjp.STUDENT_ID=sja.STUDENT_ID AND sjp.ADDRESS_ID=a.ADDRESS_ID) ORDER BY CUSTODY ASC,STUDENT_RELATION")
					,array(),array('ADDRESS_ID'));
				foreach($addresses_RET as $address_id=>$contacts)
				{
					$address = $contacts[1];
					echo '<BR>';
					echo '<!-- NEED 3 -->';
					echo '<font size=+1>'.$address['ADDRESS'].'<BR>'.($address['CITY']?$address['CITY'].', ':'').$address['STATE'].($address['ZIPCODE']?' '.$address['ZIPCODE']:'').'</font><BR><BR>';
					foreach($contacts as $contact)
					{
						if(is_numeric($contact['PERSON_ID']))
						{
							$info_RET = DBGet(DBQuery("SELECT ID,TITLE,VALUE FROM PEOPLE_JOIN_CONTACTS WHERE PERSON_ID='".$contact['PERSON_ID']."'"));
							echo '<!-- NEED '.(count($info_RET)+1).'-->';
							echo '<TABLE width=300>';
							echo '<TR><TD width=15></TD><TD width=285>';
							echo '<B>'.$contact['FIRST_NAME'].' '.($contact['MIDDLE_NAME']?$contact['MIDDLE_NAME'].' ':'').$contact['LAST_NAME'].($contact['STUDENT_RELATION']?': '.$contact['STUDENT_RELATION']:'').' &nbsp;</B><BR>';
							echo '</TD></TR>';
							if(count($info_RET))
							{
								echo '<TR><TD width=15></TD><TD width=285><TABLE>';
								foreach($info_RET as $info)
								{
									echo '<TR>';
									echo '<TD align=right><font color=gray>'.$info['TITLE'].'</font></TD>';
									echo '<TD> &nbsp; '.$info['VALUE'].'</TD>';
									echo '</TR>';
								}
								echo '</TABLE></TD></TR>';
								echo '<TR><TD colspan=2 width=300><BR></TD></TR>';
							}
							echo '</TABLE>';
						}
					}
				}
				echo '<BR><BR>';
			}
			if($_REQUEST['categories'][2]=='Y')
			{
				echo '<!-- NEED 4 -->';
	//			echo '<!-- NEW PAGE -->';
				DrawHeader(_('Medical'));
				include($staticpath.'modules/Students/includes/Medical.inc.php');
				echo '<BR><BR>';
			}
			foreach($categories_RET as $category)
			{
				if($_REQUEST['categories'][$category['ID']]!='Y')
					continue;

				echo '<!-- NEED 4 -->';
				$_REQUEST['category_id'] = $category['ID'];
				DrawHeader($category['TITLE']);
				include($staticpath.'modules/Students/includes/Other_Info.inc.php');
				echo '<BR><BR>';
			}
			echo '<!-- NEW PAGE -->';
		}
		PDFStop($handle);
	}
	else
		BackPrompt(_('No Students were found.'));
	unset($_SESSION['student_id']);
}
?>